package com.ruoyi.wgjlcData.service.impl;

import com.alibaba.fastjson2.JSON;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.wgjlcData.domain.plat.DataWgjlcYanduji;
import com.ruoyi.wgjlcData.domain.vo.TestYd;
import com.ruoyi.wgjlcData.mapper.DataWgjlcYandujiMapper;
import com.ruoyi.wgjlcData.service.IDataWgjlcYandujiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.Future;


/**
 * 无轨胶轮车烟度计测试项Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-02-27
 */
@Service
public class DataWgjlcYandujiServiceImpl implements IDataWgjlcYandujiService
{
    @Autowired
    private DataWgjlcYandujiMapper dataWgjlcYandujiMapper;

    /**
     * 查询无轨胶轮车烟度计测试项
     * 
     * @param yandujiId 无轨胶轮车烟度计测试项主键
     * @return 无轨胶轮车烟度计测试项
     */
    @Override
    public DataWgjlcYanduji selectDataWgjlcYandujiByYandujiId(Long yandujiId)
    {
        return dataWgjlcYandujiMapper.selectDataWgjlcYandujiByYandujiId(yandujiId);
    }

    /**
     * 查询无轨胶轮车烟度计测试项列表
     * 
     * @param dataWgjlcYanduji 无轨胶轮车烟度计测试项
     * @return 无轨胶轮车烟度计测试项
     */
    @Override
    public List<DataWgjlcYanduji> selectDataWgjlcYandujiList(DataWgjlcYanduji dataWgjlcYanduji)
    {
        return dataWgjlcYandujiMapper.selectDataWgjlcYandujiList(dataWgjlcYanduji);
    }

    /**
     * 新增无轨胶轮车烟度计测试项
     * 
     * @param dataWgjlcYanduji 无轨胶轮车烟度计测试项
     * @return 结果
     */
    @Override
    public int insertDataWgjlcYanduji(DataWgjlcYanduji dataWgjlcYanduji)
    {
        dataWgjlcYanduji.setCreateTime(DateUtils.getNowDate());
        return dataWgjlcYandujiMapper.insertDataWgjlcYanduji(dataWgjlcYanduji);
    }

    /**
     * 修改无轨胶轮车烟度计测试项
     * 
     * @param dataWgjlcYanduji 无轨胶轮车烟度计测试项
     * @return 结果
     */
    @Override
    public int updateDataWgjlcYanduji(DataWgjlcYanduji dataWgjlcYanduji)
    {
        dataWgjlcYanduji.setUpdateTime(DateUtils.getNowDate());
        //list转Json字符串
        if(!dataWgjlcYanduji.getTestYdList().isEmpty()) {
            dataWgjlcYanduji.setDataList(JSON.toJSONString(dataWgjlcYanduji.getTestYdList()));
        }
        return dataWgjlcYandujiMapper.updateDataWgjlcYanduji(dataWgjlcYanduji);
    }

    /**
     * 查询无轨胶轮车-烟度计测试项
     *
     * @param dataTaskId
     * @return 无轨胶轮车-烟度计测试项
     */
    @Async("threadPoolKy")
    @Override
    public Future<List<DataWgjlcYanduji>> selectDataWgjlcYandujiByDataTaskId(Long dataTaskId) {
        List<DataWgjlcYanduji> dataWgjlcYandujiEntities = dataWgjlcYandujiMapper.selectDataWgjlcYandujiByDataTaskId(dataTaskId);
        if (dataWgjlcYandujiEntities.size() != 0) {
            dataWgjlcYandujiEntities.forEach(item -> {
                if (item.getDataList() != null && item.getDataList().length() != 0) {
                    item.setTestYdList(JSON.parseArray(item.getDataList(), TestYd.class));
                    item.setListSize(item.getTestYdList().size());
                }
            });
        }
        return new AsyncResult<>(dataWgjlcYandujiEntities);
    }

    /**
     * 修改状态为2
     *
     * @param dataTaskId
     */
    @Override
    public int updateDataWgjlcYandujiByDataTaskId(Long dataTaskId) {
        return dataWgjlcYandujiMapper.updateDataWgjlcYandujiByDataTaskId(dataTaskId);
    }

    /**
     * 批量新增无轨胶轮车-烟度计测试项
     *
     * @param dataWgjlcYanduji 无轨胶轮车-烟度计测试项
     * @return 结果
     */
    @Override
    public int batchDataWgjlcYanduji(List<DataWgjlcYanduji> dataWgjlcYanduji) {
        return dataWgjlcYandujiMapper.batchDataWgjlcYanduji(dataWgjlcYanduji);
    }

    /**
     * 批量删除无轨胶轮车烟度计测试项
     * 
     * @param yandujiIds 需要删除的无轨胶轮车烟度计测试项主键
     * @return 结果
     */
    @Override
    public int deleteDataWgjlcYandujiByYandujiIds(Long[] yandujiIds)
    {
        return dataWgjlcYandujiMapper.deleteDataWgjlcYandujiByYandujiIds(yandujiIds);
    }

    /**
     * 删除无轨胶轮车烟度计测试项信息
     * 
     * @param yandujiId 无轨胶轮车烟度计测试项主键
     * @return 结果
     */
    @Override
    public int deleteDataWgjlcYandujiByYandujiId(Long yandujiId)
    {
        return dataWgjlcYandujiMapper.deleteDataWgjlcYandujiByYandujiId(yandujiId);
    }
}
